/*
 * 3-30-14.  Creating a Sector class with Jason.
 * Possible Sector fields:  (3-17-14)
 *   1.  Boundaries (Rectangle2D).
 *   2.  Camps  (Polygon).
 *   3.  Center  (in SectorXY[][5 and 6], becomes Point2D).
 *   4.  Sorted  (boolean).
 *   5.  Ritual Center  (Rectangle2D).
 *   6.  Carrying Capacity  (int).
 *   7.  Player/Decider (I-IV, player or computer).
 *   8.  Invaded  (to be determined).
 *   9.  Subject Loyalty  (to be determined).
 */
package ecop017;

import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Collections;
import java.awt.Graphics2D;

public class Sector {

  CopyOnWriteArrayList<Camp> camps = new CopyOnWriteArrayList<>();
  private  Shape    boundaries;
  private  Point2D  center;
  protected int     carryCap1;
  protected double  politicalFund;
  protected double  loyaltyIndex;
  protected double  warFund;
  protected boolean sorted = false;
  protected boolean feast = false;
  private   Shape   ritualCenter;

  Sector(int x, int y, int w, int h, int xc, int yc, int cC1) {
    boundaries = new Rectangle2D.Float(x,y,w,h);
    center = new Point2D.Double(xc,yc);
    carryCap1 = cC1; 
    ritualCenter = new Rectangle2D.Double(center.getX()-5, center.getY()-5, 10, 10);
    
    politicalFund = 0.0;
    loyaltyIndex = 0.8;
    warFund = 0.0;
  }
  
  Sector(int[] args)  {
    this(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
  }
  
  protected void update() {     //setPoliticalFunds()  {
    politicalFund = camps.size() * 0.25;
 
    //  Subtract from Political Fund if feast given.
    if(feast) {
      politicalFund -= 3.0;  //The feast decreases politicalFund by 3.0.
      feast = false;
    }

    //  Set loyaltyIndex to drop 5% with every additional camp over CC1.
    loyaltyIndex -= (camps.size() - carryCap1) * 0.05;

    //If loyaltyIndex falls below 0.5, have a feast!
    if(loyaltyIndex < 0.5)  {
      feast = true; 
    }

    if(feast) {
      loyaltyIndex = loyaltyIndex + 0.3;
    }
    
  }

  protected Shape getBoundaries()  {
    return boundaries;
  }

  protected Point2D getCenter() {
    return center;
  }

  protected int getCarryCap1() {
    return carryCap1;
  }

  protected Double getPoliticalFund()  {
      return politicalFund;
  }
  
  protected boolean setFeast(boolean tf)  {
      return feast;
  }
    
  protected Double getLoyaltyIndex()  {
      return loyaltyIndex;
  }

  protected void addCamp(Camp c)  {
    camps.add(c);
  }

  protected CopyOnWriteArrayList<Camp> getCamps()  {
    return camps;
  }

  protected void sortCamps()  {
    Collections.sort(camps);  
    sorted = true;
  }
  
  protected boolean getSorted() {
      return sorted;
  }
  
  protected void paint(Graphics2D g) {  
    //  If pop > CC1, add ritual center icon.
    g.setColor(Color.WHITE);
    if(camps.size() > carryCap1)
        g.fill(ritualCenter);

    for(Camp c : camps) {
        c.paint(g);
    }
  }
}



